package com.example.administrator.printoutindemo;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.widget.ListView;

import com.dds.soap.SoapListener;
import com.dds.soap.SoapParams;
import com.example.administrator.printoutindemo.adapter.QuyangAdapter;
import com.example.administrator.printoutindemo.base.BaseActivity;
import com.example.administrator.printoutindemo.bean.ZhiliangquyangBean;
import com.example.administrator.printoutindemo.http.SPUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jess.arms.base.BaseConstants;

import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;

import java.util.ArrayList;
import java.util.List;

public class QuyangFengqianyuanActivity extends BaseActivity {
    private static String[] PERMISSIONS_REQUEST = {
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.CAMERA
    };
    private ListView lv_zlcylist;
    private List<ZhiliangquyangBean> mlist;
    private QuyangAdapter mAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.quyangfengqian);
        if (ActivityCompat.checkSelfPermission(QuyangFengqianyuanActivity.this,
                Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(QuyangFengqianyuanActivity.this,
                    PERMISSIONS_REQUEST, 100);
        }
        lv_zlcylist = (ListView) findViewById(R.id.lv_zlcylist);
        mlist = new ArrayList<>();
        mAdapter = new QuyangAdapter(QuyangFengqianyuanActivity.this, mlist);
        lv_zlcylist.setAdapter(mAdapter);


    }

    @Override
    protected void onResume() {
        super.onResume();
        simpleGetterTaskList() ;
    }

    private void simpleGetterTaskList() {


        String methodName = "SimpleGetterTaskList";

        SoapParams params = new SoapParams();
        params.put("userId", SPUtil.getString(QuyangFengqianyuanActivity.this, "iduser", ""));

        /**
         * 请求
         */
        soapUtil.callEntry(getUrl(), BaseConstants.NAME_SPACE, methodName, params, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {

                String result = object.getProperty(methodName + "Result").toString();
                if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100")) {
                    mAdapter.shua();
                    List<ZhiliangquyangBean> inKuBean = new Gson().fromJson(result, new TypeToken<List<ZhiliangquyangBean>>() {
                    }.getType());
                    mAdapter.addAll(inKuBean);
                } else {

                }

            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
            }
        }, getAapiUserName(), getApiPwd());
    }
}
